<?php

class CommentsController extends Zend_Controller_Action
{
	public function indexAction()
	{
	}
	
	public function addAction(){
		$form = new Application_Form_Comments();
		$this->view->form = $form;
		$auth = Zend_Auth::getInstance();
		if ($this->getRequest()->isPost()) {
			$formData = $this->getRequest()->getPost();
			if ($form->isValid($formData)) {

				$user = $auth->getIdentity()->username;
				$comment = $form->getValue('text');
				$index = $this->_getParam('id');
				$comments = new Application_Model_DbTable_Comments();
		
				$comments->addComment($user,$comment,$index);
				$this->_helper->redirector('voir','article',null,array('id'=> $index));
			} else {
				$this->view->form = $form;
		
			}
		
		}
	}


}